//
//  dElHEfJLCFHomeViewControllerjuYxzb.m
//  Dvjf_ios
//
//  Created by Ji on 2018/9/6.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "dElHEfJLCFHomeViewControllerjuYxzb.h"
#import "IpxzlFJLCFHomeRequestPfjhYJ.h"
#import "uzZucYJLCFHomeBmapModelAwTcXU.h"
#import "rmMqyfJLCFLoginAndRegisterControllerFbzYtj.h"
#import "wUGBczJLCFHomeMsgCenterControllerlMWSIn.h"
#import "mbSCEGJLCFHomeHeaderViewsYEtrK.h"
#import "FQjcojJLCFHomeModuleCelltAzsUX.h"
#import "HFCsIrJLCFHomeNewBmapCellwxSIog.h"
#import "uXnlJqJLCFHomeBmapListCellqPDupe.h"
#import "sHkPtEJLCFMineRequestozAYZs.h"
#import "zhnAbhJLCFHomeNoticeCellFeiqWd.h"

@interface dElHEfJLCFHomeViewControllerjuYxzb ()

@property (nonatomic, strong) mCELYoJLCFHomeIndexDataModelsAqBSs *KvBViKhomeIndexDataModelQtoLdG;

@property (nonatomic, strong) UIImageView *zdgYsQactivityImgFSTOnM;

@property (nonatomic, strong) mbSCEGJLCFHomeHeaderViewsYEtrK *rRHNlxheaderViewfJQeRl;

@property (nonatomic, strong) uzZucYJLCFHomeBmapModelAwTcXU *TWKLAgoneBmapModelZTxBvk;

@property (nonatomic, strong) NSMutableArray *QVdfMwbmapArrWKXWGt;

@end

@implementation dElHEfJLCFHomeViewControllerjuYxzb

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.frame = CGRectMake(0, 0, FULL_WIDTH, FULL_HEIGHT - TABBAR_HEIGHT);
    self.tableView.frame = CGRectMake(0, 0, FULL_WIDTH, self.view.height);
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 175)];
    self.tableView.backgroundColor = QTZ_Gray237;
    self.tableView.mj_footer.hidden = YES;

    [self loadData];
    
}

- (void)addNavigationBar
{
//    [super addNavigationBar];
//    self.navigationBar.title = @"金鲤财富";
//    self.zdgYsQactivityImgFSTOnM = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_home_activity"]];
//    [self.zdgYsQactivityImgFSTOnM sizeToFit];
//    self.zdgYsQactivityImgFSTOnM.right = FULL_WIDTH - 10;
//    self.zdgYsQactivityImgFSTOnM.centerY = NAVBAR_CENTER_Y;
//    self.zdgYsQactivityImgFSTOnM.userInteractionEnabled = YES;
//    [self.zdgYsQactivityImgFSTOnM bk_whenTapped:^{
//        if ([JLCFRegisterService shareService].hasToken) {
//            [[JLCFApplicationEntrace shareEntrance].currentNavController pushViewController:[wUGBczJLCFHomeMsgCenterControllerlMWSIn new] animated:YES];
//        } else {
//            LoginAndRegisterController *vc = [LoginAndRegisterController new];
//            [[[JLCFApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
//        }
//    }];
//    [self.navigationBar addSubview:self.zdgYsQactivityImgFSTOnM];
    
}

- (NSMutableArray *)QVdfMwbmapArrWKXWGt {
    if (!_QVdfMwbmapArrWKXWGt) {
        _QVdfMwbmapArrWKXWGt = [NSMutableArray array];
    }
    return _QVdfMwbmapArrWKXWGt;
}

- (mbSCEGJLCFHomeHeaderViewsYEtrK *)rRHNlxheaderViewfJQeRl {
    if (!_rRHNlxheaderViewfJQeRl) {
        _rRHNlxheaderViewfJQeRl = [[mbSCEGJLCFHomeHeaderViewsYEtrK alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, FitRealValue(400))];
    }
    return _rRHNlxheaderViewfJQeRl;
}

- (void)loadData {
    [self.QVdfMwbmapArrWKXWGt removeAllObjects];
    [IpxzlFJLCFHomeRequestPfjhYJ postHomeDataWithParams:@{@"channel" : @"iOS"} loadingInView:self.tableView success:^(mCELYoJLCFHomeIndexDataModelsAqBSs *home) {
        
        [self.rRHNlxheaderViewfJQeRl reloadWithBanners:home.bannerlist];
        self.tableView.tableHeaderView = self.rRHNlxheaderViewfJQeRl;
        self.KvBViKhomeIndexDataModelQtoLdG = home;
        [self congfiData];
        [self configFooter];
        [self.tableView reloadData];
        [self endRefresh];
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
}

- (void)congfiData {
    for (uzZucYJLCFHomeBmapModelAwTcXU *model in self.KvBViKhomeIndexDataModelQtoLdG.bmap) {
        if ([model.use isEqualToString:@"0"]) {
            self.TWKLAgoneBmapModelZTxBvk = model;
        } else {
            [self.QVdfMwbmapArrWKXWGt addSafeObject:model];
        }
    }
}

- (void)configFooter {
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, FitRealValue(240))];
    
    UIImageView *stepImageView = [[UIImageView alloc] init];
    [footer addSubview:stepImageView];
    stepImageView.image = [UIImage imageNamed:@"icon_home_footer"];
    stepImageView.frame = CGRectMake(0, 0, FULL_WIDTH, FitRealValue(240));
    
    
//    UILabel *GAvcnIamountLabelMphKiM = [UILabel labelWithText:self.KvBViKhomeIndexDataModelQtoLdG.totalBuy textColor:QTZ_Gray102 font:FONT(18)];
//    GAvcnIamountLabelMphKiM.centerX = FULL_WIDTH / 2;
//    GAvcnIamountLabelMphKiM.centerY = 35;
//    [footer addSubview:GAvcnIamountLabelMphKiM];
//
//    UILabel *amountTitleLabel = [UILabel labelWithText:@"金鲤财富总交易额（元）" textColor:QTZ_Gray153 font:FONT(7)];
//    amountTitleLabel.centerX = GAvcnIamountLabelMphKiM.centerX;
//    amountTitleLabel.bottom = GAvcnIamountLabelMphKiM.top - 8;
//    [footer addSubview:amountTitleLabel];
//
//    UILabel *securyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, GAvcnIamountLabelMphKiM.bottom + 8, 240, 15)];
//    securyLabel.textColor = QTZ_Gray153;
//    securyLabel.font = FONT(8);
//    securyLabel.textAlignment = NSTextAlignmentCenter;
//    NSTextAttachment *textAttach = [[NSTextAttachment alloc] init];
//    textAttach.image = [UIImage imageNamed:@"icon_home_secury"];
//    textAttach.bounds = CGRectMake(-4, -2, 10, 11);
//    NSAttributedString * securyAttach = [NSAttributedString attributedStringWithAttachment:textAttach];
//    NSMutableAttributedString *securyAttributeString = [[NSMutableAttributedString alloc] initWithAttributedString:securyAttach];
//    NSMutableAttributedString *orginalAttributString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"过往本息100%%安全兑现"]];
//    [securyAttributeString appendAttributedString:orginalAttributString];
//    securyLabel.attributedText = securyAttributeString;
//    securyLabel.centerX = GAvcnIamountLabelMphKiM.centerX;
//    [footer addSubview:securyLabel];
    
    self.tableView.tableFooterView = footer;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            return 30;
            break;
        case 1:
            return 100;
            break;
        case 2:
            return 220;
            break;
        case 3:
            return 260;
            break;
        default:
            return 0;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section == 0) {
        zhnAbhJLCFHomeNoticeCellFeiqWd *cell = [zhnAbhJLCFHomeNoticeCellFeiqWd dequeueReusableCellForTableView:tableView];
        cell.JRuIeDnoticeArrayQGgqZz = self.KvBViKhomeIndexDataModelQtoLdG.indexMsg;
        return cell;
    }
    
    if (indexPath.section == 1) {
        FQjcojJLCFHomeModuleCelltAzsUX *cell = [FQjcojJLCFHomeModuleCelltAzsUX dequeueReusableCellForTableView:tableView];
        [cell reloadData];
        return cell;
    } else if (indexPath.section == 2) {
        HFCsIrJLCFHomeNewBmapCellwxSIog *cell = [HFCsIrJLCFHomeNewBmapCellwxSIog dequeueReusableCellForTableView:tableView];
        cell.model = self.TWKLAgoneBmapModelZTxBvk;
        [cell reloadData];
        return cell;
    } else if (indexPath.section == 3) {
        HomeBmapListCell *cell = [HomeBmapListCell dequeueReusableCellForTableView:tableView];
        cell.QVdfMwbmapArrWKXWGt = self.QVdfMwbmapArrWKXWGt;
        [cell reloadData];
        return cell;
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 10)];
    rRHNlxheaderViewfJQeRl.backgroundColor = [UIColor clearColor];
    return rRHNlxheaderViewfJQeRl;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}


@end
